package com.yanggu.mapreduce.sort;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2020/2/6 15:06
 * @description:
 */
public class CustomizePartitioner extends Partitioner<FlowBean, Text> {

    @Override
    public int getPartition(FlowBean flowBean, Text text, int numPartitions) {
        //得到手机号的前三位
        String preNumber = text.toString().substring(0, 3);

        int partition = 4;

        //判断属于哪个分区
        switch (preNumber) {
            case "136":
                partition = 0;
                break;
            case "137":
                partition = 1;
                break;
            case "138":
                partition = 2;
                break;
            case "139":
                partition = 3;
                break;
            default:
        }
        return partition;
    }
}
